home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / TRSOUNIT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  5.2 KB  |  173 lines

  1. // trsounit.cpp: Trso class implementation
  2. // These routines use the built-in rectangle to clip any screen
  3. // transfers. They also take care of the mouse cursor as well.
  4.  
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include "trsounit.h"
  8.  
  9. Trso::Trso(TxBuff *T) : Rso(0, 0, 0, 0)
  10. // Initializes a rectangle and sets up the texel buffer
  11. {
  12.   if (T == 0) {
  13.      Pic = new TxBuff(0);
  14.   }
  15.   else {
  16.     Pic = new TxBuff(T->Txram);
  17.     Rso::SetSize(T->Wd, T->Ht);
  18.     Pic->SetSize(T->Wd, T->Ht);
  19.   }
  20. }
  21.  
  22. Trso::~Trso(void)
  23. // De-allocates the texel buffer 
  24. {
  25.   delete Pic;
  26. }
  27.  
  28. void Trso::SetSize(int W, int H)
  29. // Sets the size of a rectangle. If the rectangle's buffer
  30. // isn't aliased (which means it was allocated on the heap),
  31. // the buffer is re-sized as well. 
  32. {
  33.   Rso::SetSize(W, H);
  34.   if (!Pic->Aliased) Pic->SetSize(W, H);
  35. }
  36.  
  37. void Trso::SetLocn(int Xl, int Yl)
  38. // Sets the rectangle's location && the origin reference
  39. // (OrgPtr) in the texel buffer 
  40. {
  41.   Rso::SetLocn(Xl, Yl);
  42.   Pic->SetLocn(Xl, Yl);
  43. }
  44.  
  45. void Trso::HzWrt(int X, int Y, char *Str, char Attr)
  46. // Writes a string horizontally in a specified attribute. 
  47. // Supports both left- and right-hand clipping. 
  48. {
  49.   int Cnt, Offset;
  50.   Cnt = strlen(Str);
  51.   if (X < 0) Offset = -X; else Offset = 0; 
  52.   if (HzClip(X,Y,Cnt)) {
  53.      Mouse.Hide();
  54.      Pic->HzWrt(X,Y,Str+Offset,Attr,Cnt);
  55.      Mouse.Show();
  56.   }
  57. }
  58.  
  59. void Trso::HzWrtB(int X, int Y, char *Str)
  60. // Writes a string horizontally without changing the screen 
  61. // attribute. Supports both left- and right-hand clipping. 
  62. {
  63.   int Cnt, Offset;
  64.   Cnt = strlen(Str);  
  65.   if (X < 0)  Offset = -X; else Offset = 0; 
  66.   if (HzClip(X,Y,Cnt))  {
  67.      Mouse.Hide();
  68.      Pic->HzWrtB(X,Y,Str+Offset,Cnt);
  69.      Mouse.Show();
  70.   }
  71. }
  72.  
  73. void Trso::Fill(int X, int Y, int W, int H, char Ch, char Attr)
  74. // Fills a rectangular region with both a character && an
  75. // attribute. Supports clipping on all sides. Note the checks 
  76. // for a horizontal (single row) and vertical (single column) 
  77. // fills so that the clipping works correctly. 
  78. {
  79.   if (((H == 1) && HzClip(X, Y, W)) ||
  80.       ((W == 1) && VtClip(X, Y, H)) ||
  81.       (VtClip(X,Y,H) && HzClip(X,Y,W)))  {
  82.      Mouse.Hide();
  83.      Pic->Fill(X, Y, W, H, Ch, Attr);
  84.      Mouse.Show();
  85.   }
  86. }
  87.  
  88. void Trso::FillB(int X, int Y, int W, int H, char Ch, char Opt)
  89. // Fills a rectangular region with either a character or an
  90. // attribute, but not both. Here's how the control parameter
  91. // works:
  92. //
  93. //  Opt == 0 -- character fill 
  94. //  Opt == 1 -- attribute fill
  95. //
  96. // Clipping is performed on all four sides. !e the checks for a
  97. // horizontal (single row) && vertical (single column) fills so that 
  98. // the clipping is performed properly. 
  99. {
  100.   if (((H == 1) && HzClip(X, Y, W)) || // Single row 
  101.       ((W == 1) && VtClip(X, Y, H)) || // Single column
  102.       (VtClip(X,Y,H) && HzClip(X,Y,W))) {
  103.      Mouse.Hide();
  104.      Pic->FillB(X, Y, W, H, Ch, Opt);
  105.      Mouse.Show();
  106.   }
  107. }
  108.  
  109. void Trso::Box(int X, int Y, int W, int H, char Ba, char Attr)
  110. // Draws a text-based box of a specified style and width 
  111. {
  112.   unsigned char Bw, Bs, I;
  113.   Bw = (unsigned char)Ba & 0x000f;         // Unpack the border width
  114.   Bs = ((unsigned char)Ba >> 4) & 0x000f;  // Unpack the border style
  115.   Mouse.Hide();
  116.   if ((Bs < 4))  {
  117.      for (I = 0; I<Bw; I++, X++, Y++, W-=2, H-=2) {
  118.        Fill(X, Y, W, 1, LineChars[Bs][HzBar], Attr);
  119.        Fill(X, Y, 1, H, LineChars[Bs][VtBar], Attr);
  120.        Fill(X, Y, 1, 1, LineChars[Bs][Ulc], Attr);
  121.        Fill(X+W-1, Y, 1, H, LineChars[Bs][VtBar], Attr);
  122.        Fill(X+W-1, Y, 1, 1, LineChars[Bs][Urc], Attr);
  123.        Fill(X, Y+H-1, W, 1, LineChars[Bs][HzBar], Attr);
  124.        Fill(X, Y+H-1, 1, 1, LineChars[Bs][Llc], Attr);
  125.        Fill(X+W-1, Y+H-1, 1, 1, LineChars[Bs][Lrc], Attr);
  126.      }
  127.   }
  128.   Mouse.Show();
  129. }
  130.  
  131. void Trso::Scroll(ScrollDir Sd, int Amt)
  132. // Scrolls the region defined by the rectangle. The region
  133. // can be scrolled up or down a specified amount. 
  134. {
  135.   Mouse.Hide();
  136.   Pic->Scroll(0, 0, Wd, Ht, Sd, Amt);
  137.   Mouse.Show();
  138. }
  139.  
  140. void Trso::Swap(int X, int Y, int W, int H, Trso *Other, int Xs, int Ys)
  141. // Swaps data between this Self's Pic buffer and another Trso's Pic. The 
  142. // Other Pic region starts at (Xs, Ys) and Self's Pic region starts 
  143. // at X,Y. The swapping region is W by H in size. The coordinates 
  144. // are checked to ensure that they are in range and the width && 
  145. // height are clipped if necessary. 
  146. {
  147.   if (HzClip(X,Y,W) && Other->HzClip(Xs,Ys,W))  {
  148.      if (VtClip(X,Y,H) && Other->VtClip(Xs,Ys,H))  {
  149.         Mouse.Hide();
  150.         Pic->Swap(X, Y, W, H, Other->Pic, Xs, Ys);
  151.         Mouse.Show();
  152.      }
  153.   }
  154. }
  155.  
  156. void Trso::Xfr(int X, int Y, int W, int H, Trso *Src, int Xs, int Ys)
  157. // Transfers data from the Src Trso Pic region, starting at (Xs, Ys)
  158. // to the Self's Pic region, starting at X,Y. The region transferred 
  159. // has size W by H. The coordinates are checked to ensure they are in 
  160. // range && the width && height are clipped if necessary. 
  161. {
  162.   if (HzClip(X,Y,W) && Src->HzClip(Xs,Ys,W)) {
  163.      if (VtClip(X,Y,H) && Src->VtClip(Xs,Ys,H)) {
  164.         Mouse.Hide();
  165.         Pic->Xfr(X, Y, W, H, Src->Pic, Xs, Ys);
  166.         Mouse.Show();
  167.      }
  168.   }
  169. }
  170.  
  171.  
  172.  
  173.